<?php

namespace app\modules\admin\controllers;

use app\common\services\StaticServices;
use yii\web\Controller;
use Yii;
use app\models\Member;

class MemberController extends Controller
{
    public function actionIndex()
    {
        $p = intval(Yii::$app->request->get('p', 1));
        $member_info = Member::find();

        $page_size = StaticServices::$page;
        $total_count = $member_info->count();
        $total_page = ceil($total_count / $page_size);

        $list = $member_info->offset(($p - 1) * $page_size)->orderBy(['create_time' => SORT_DESC])->limit($page_size)->all();

        return $this->render('index', ['list' => $list, 'p' => $p, 'total_page' => $total_page]);
    }

    public function actionSet()
    {
        $member_id = intval(Yii::$app->request->get('id', 0));
        $member_info = [];
        if ($member_id) {
            $member_info = Member::find()->where(['id' => $member_id])->one();
        }

        return $this->render('set', ['info' => $member_info]);
    }
}